//
//  CProduct.h
//  HCHK_iphone
//
//  Created by yilong zhang on 11-12-11.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CDownLoadManager.h"
#import "CCommentary.h"
#import "CCondition.h"
#import "AppConfig.h"
#import "Message.h"
#import "CUser.h"

//@"http://bindapple.com/wp-content/uploads/2011/09/iphone-help-2.jpg";//

#define Product_Properties_Num  21

@class CCommentary;

@protocol ProductDelegate <NSObject>

@optional
-(void)DidDownLoadImage:(id)product Image:(NSData*)image;
-(void)DidDownLoadPubIcon:(id)product Image:(NSData*)image;
-(void)DidDownLoadSubImage:(id)product Image:(NSData*)image Object:(id)object;
-(void)DidDownLoadCommentaries:(id)product Commetaries:(NSArray*)coms;
-(void)DidDownLoadSuccess:(id)product OpType:(int)optype Index:(int)index Info:(NSString*)info;
-(void)DidDownLoadError:(id)product OpType:(int)optype;

@end

@interface CProduct : NSObject <OperationDelegate>

@property (nonatomic, assign) id<ProductDelegate>   delegate;

@property (nonatomic, retain) NSNumber * P_AID;
@property (nonatomic, retain) NSNumber * P_Publisher;
@property (nonatomic, retain) NSNumber * P_Date;

@property (nonatomic, retain) NSString * P_Icon;
@property (nonatomic, retain) NSString * P_Image;
@property (nonatomic, retain) NSString * P_UrlImage;
@property (nonatomic, retain) NSString * P_Name;
@property (nonatomic, retain) NSString * P_UrlIcon;
@property (nonatomic, retain) NSString * P_Position;
@property (nonatomic, retain) NSString * P_Caption;
@property (nonatomic, retain) NSString * P_ResName;
@property (nonatomic, retain) NSString * P_City;
@property (nonatomic, retain) NSString * P_PubName;
@property (nonatomic, retain) NSString * P_PubIcon;
@property (nonatomic, retain) NSString * P_PubIconUrl;
@property (nonatomic, retain) NSString * P_SubImage;
@property (nonatomic, retain) NSString * P_SubImgUrl;

@property (nonatomic, retain) NSNumber * P_Price;
@property (nonatomic, retain) NSNumber * P_JDu;
@property (nonatomic, retain) NSNumber * P_WDu;

@property (nonatomic, retain) NSNumber * P_Eat;
@property (nonatomic, retain) NSNumber * P_Want;
@property (nonatomic, retain) NSNumber * P_Nice;

@property (nonatomic, assign) long  m_lFollowID;

//@property (nonatomic, assign) NSMutableArray   *m_Coms;

//@property (nonatomic, assign) BOOL         m_IsIconNil;
@property (nonatomic, assign) BOOL         m_IsIconLoad;
@property (nonatomic, retain) CTask      * m_IconOpID;

//@property (nonatomic, assign) BOOL         m_IsImageNil;
@property (nonatomic, assign) BOOL         m_IsImageLoad;
@property (nonatomic, retain) CTask      * m_ImageOpID;

@property (nonatomic, assign) BOOL  m_IsPubIconLoad;
@property (nonatomic, retain) CTask *m_PubIconOpID;

@property (nonatomic, retain) CTask      * m_ComOpID;
@property (nonatomic, retain) CTask      * m_EatOpID;
@property (nonatomic, retain) CTask      * m_WantOpID;
@property (nonatomic, retain) CTask      * m_NiceOpID;

@property (nonatomic, assign) BOOL          m_bIsLoadCom;
@property (nonatomic, assign) CAscCounter   * m_AscCounter;
@property (nonatomic, assign) CDesCounter   * m_DesCounter;

//评价
@property (nonatomic, assign) BOOL  m_bIsEated;
@property (nonatomic, assign) BOOL  m_bIsWanted;
@property (nonatomic, assign) BOOL  m_bIsNiced;

@property (nonatomic, assign) NSMutableArray    *m_SubTask;
//commentaries
//@property (nonatomic, assign) id    m_ShowComsTarget;
//@property (nonatomic, assign) SEL   m_ShowComsAction;

//view
@property (nonatomic, retain) UIImageView *m_IconView;
@property (nonatomic, retain) UIImageView *m_ImageView;
@property (nonatomic, assign) UIImageView *m_PubIconView;

@property (nonatomic, assign) int   m_Index;
@property (nonatomic, assign) int   m_nState;   //1已经关注，0未关注

+(int)CreateProdutTable:(NSString*)tablename;
+(int)GetProuctsTotal:(NSString*)tablename Where:(NSString*)where;
+(NSArray*)GetLimitProducts:(NSString*)tablename Where:(NSString*)where Offset:(int)offset Limit:(int)limit;
+(int)UpdateProductInfo:(NSString*)tablename Where:(NSString*)where Keys:(NSArray*)keys;
+(int)RemoveProduct:(NSString*)tablename Where:(NSString*)where;

-(void)SetProductWithDic:(NSDictionary*)dic Path:(NSString*)path;
-(void)SetProductWithArr:(NSArray*)arr;
-(int)SaveProduct:(NSString*)tablename;
-(int)SaveProductWithPathes:(NSString*)table IconPath:(NSString*)iconpath ImagePath:(NSString*)imagepath;
-(int)SaveIcon:(NSData*)data;
-(int)SaveImage:(NSData*)data;
-(int)SavePubIcon:(NSData*)data;
-(BOOL)GetCommentariesFromDB;
-(void)GetCommentaries;
-(void)PublicationAppraisal:(NSString*)mobikey SessionID:(NSString*)sessionid Type:(int)type;
-(void)PublicationCommentary:(NSString*)mobikey SessionID:(NSString*)sessionid Content:(NSString*)content TmpID:(NSNumber*)tmpID;
-(void)ResetQueryConditions;
-(NSData*)GetProductIcon;
-(NSData*)GetProductImage;
-(NSData*)GetPubIcon;

//view
-(void)DownLoadIcon;
-(void)DownLoadImage;
-(void)DownLoadPubIcon;
-(void)DownLoadCommentary;
-(void)SetProductIconView:(id)view;
-(void)SetProductImageView:(id)view;
-(void)SetPdctPubIconView:(id)view;

-(void)DownLoadSubImage:(NSString*)url Object:(id)object Number:(NSNumber*)number;
-(void)CancelSubImgTask;
-(void)SaveSubImage:(int)index Data:(NSData*)data;
-(NSData*)GetSubImage:(int)index;

//download task
-(void)ProductCancelLoadIcon;
-(void)ProductCancelLoadImage;
-(void)ProductCancelLoadComs;
-(void)ProductCancelLoadPubIcon;

@end
